home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / components / dhSecretHelperProcessor.js < prev    next >
Text File  |  2010-01-15  |  6KB  |  173 lines

  1. /******************************************************************************
  2.  *            Copyright (c) 2006-2010 Michel Gutierrez. All Rights Reserved.
  3.  ******************************************************************************/
  4.  
  5. /**
  6.  * Constants.
  7.  */
  8.  
  9. const NS_SEHPROC_CID = Components.ID("{3b6dfafc-a55a-4e3b-8e2c-34584c33d676}");
  10. const NS_SEHPROC_PROG_ID = "@downloadhelper.net/secrethelper-intro-processor;1";
  11. const DHNS = "http://downloadhelper.net/1.0#";
  12.  
  13. var Util=null;
  14.  
  15. /**
  16. * Object constructor
  17. */
  18. function SehProc() {
  19.     try {
  20.         //dump("[SehProc] constructor\n");
  21.  
  22.         var prefService=Components.classes["@mozilla.org/preferences-service;1"]
  23.                                            .getService(Components.interfaces.nsIPrefService);
  24.         this.pref=prefService.getBranch("dwhelper.");
  25.         var seh=this.pref.getBoolPref("seh-intro-proc.enable");
  26.         if(seh) {    
  27.             try { // for windows only
  28.                 var reg=Components.classes["@mozilla.org/windows-registry-key;1"]
  29.                     .createInstance(Components.interfaces.nsIWindowsRegKey);
  30.                 this.core=Components.classes["@downloadhelper.net/core;1"].
  31.                     getService(Components.interfaces.dhICore);
  32.                 this.core.registerProcessor(this);
  33.             } catch(e) {}
  34.         }
  35.     } catch(e) {
  36.         dump("[SehProc] !!! constructor: "+e+"\n");
  37.     }
  38. }
  39.  
  40. SehProc.prototype = {
  41.         get name() { return "sec-download"; },
  42.         get provider() { return "SecretHelperHelper"; },
  43.         get title() { return Util.getText("processor.sec-download.title"); },
  44.         get description() { return Util.getText("processor.sec-download.description"); },
  45.         get enabled() { return true; },
  46. }
  47.  
  48. SehProc.prototype.canHandle=function(desc) {
  49.     //dump("[SehProc] canHandle()\n");
  50.     if(desc.has("media-url"))
  51.         return true;
  52.     else
  53.         return false;
  54. }
  55.  
  56. SehProc.prototype.requireDownload=function(desc) {
  57.     //dump("[SehProc] requireDownload()\n");
  58.     return false;
  59. }
  60.  
  61. SehProc.prototype.preDownload=function(desc) {
  62.     //dump("[SehProc] preDownload()\n");
  63.     return true;
  64. }
  65.  
  66. SehProc.prototype.handle=function(desc) {
  67.     //dump("[SehProc] handle()\n");
  68.     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  69.                                 .getService(Components.interfaces.nsIWindowMediator);
  70.     var w = wm.getMostRecentWindow("navigator:browser");
  71.     w.open('http://www.downloadhelper.net/secrethelper.php');
  72. }
  73.  
  74. SehProc.prototype.QueryInterface = function(iid) {
  75.     //dump("[SehProc] QueryInterface("+iid+")\n");
  76.     if(
  77.         iid.equals(Components.interfaces.dhIProcessor) ||
  78.         iid.equals(Components.interfaces.nsISupports)
  79.     ) {
  80.         return this;
  81.     }
  82.     throw Components.results.NS_ERROR_NO_INTERFACE;
  83. }
  84.  
  85. var vSehProcModule = {
  86.     firstTime: true,
  87.     
  88.     /*
  89.      * RegisterSelf is called at registration time (component installation
  90.      * or the only-until-release startup autoregistration) and is responsible
  91.      * for notifying the component manager of all components implemented in
  92.      * this module.  The fileSpec, location and type parameters are mostly
  93.      * opaque, and should be passed on to the registerComponent call
  94.      * unmolested.
  95.      */
  96.     registerSelf: function (compMgr, fileSpec, location, type) {
  97.  
  98.         if (this.firstTime) {
  99.             this.firstTime = false;
  100.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  101.         }
  102.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  103.         compMgr.registerFactoryLocation(NS_SEHPROC_CID,
  104.                                         "SehProc",
  105.                                         NS_SEHPROC_PROG_ID, 
  106.                                         fileSpec,
  107.                                         location,
  108.                                         type);
  109.     },
  110.  
  111.     unregisterSelf: function(compMgr, fileSpec, location) {
  112.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  113.         compMgr.unregisterFactoryLocation(NS_DH_SEHPROC_CID, fileSpec);
  114.     },
  115.  
  116.     /*
  117.      * The GetClassObject method is responsible for producing Factory and
  118.      * SingletonFactory objects (the latter are specialized for services).
  119.      */
  120.     getClassObject: function (compMgr, cid, iid) {
  121.         if (!cid.equals(NS_SEHPROC_CID)) {
  122.             throw Components.results.NS_ERROR_NO_INTERFACE;
  123.         }
  124.  
  125.         if (!iid.equals(Components.interfaces.nsIFactory)) {
  126.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  127.         }
  128.  
  129.         return this.vSehProcFactory;
  130.     },
  131.  
  132.     /* factory object */
  133.     vSehProcFactory: {
  134.         /*
  135.          * Construct an instance of the interface specified by iid, possibly
  136.          * aggregating it with the provided outer.  (If you don't know what
  137.          * aggregation is all about, you don't need to.  It reduces even the
  138.          * mightiest of XPCOM warriors to snivelling cowards.)
  139.          */
  140.         createInstance: function (outer, iid) {
  141.             if (outer != null) {
  142.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  143.             }
  144.     
  145.             if(Util==null) 
  146.                 Util=Components.classes["@downloadhelper.net/util-service;1"]
  147.                     .getService(Components.interfaces.dhIUtilService);
  148.  
  149.             return new SehProc().QueryInterface(iid);
  150.         }
  151.     },
  152.  
  153.     /*
  154.      * The canUnload method signals that the component is about to be unloaded.
  155.      * C++ components can return false to indicate that they don't wish to be
  156.      * unloaded, but the return value from JS components' canUnload is ignored:
  157.      * mark-and-sweep will keep everything around until it's no longer in use,
  158.      * making unconditional ``unload'' safe.
  159.      *
  160.      * You still need to provide a (likely useless) canUnload method, though:
  161.      * it's part of the nsIModule interface contract, and the JS loader _will_
  162.      * call it.
  163.      */
  164.     canUnload: function(compMgr) {
  165.         return true;
  166.     }
  167. };
  168.  
  169. function NSGetModule(compMgr, fileSpec) {
  170.     return vSehProcModule;
  171. }
  172.  
  173.